<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

    class Contact extends CI_Controller { 
        
        public function index() {
            $data['title'] = 'Contact us';
            $data['main_content'] = 'contact_view';
            $data['curr_page'] = 5;
            $this->load->view('template',$data);
        }
        
        function contactUs() {
            $name = $this->input->post('name');
            $email = $this->input->post('email');
            $msg = $this->input->post('message');
            
            $this->form_validation->set_rules('name', 'Name', 'required|min_length[4]');
            $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
            $this->form_validation->set_rules('message', 'Message', 'required|min_length[20]');
            if($this->form_validation->run() == FALSE) {
                $data['main_content'] = 'contact_view';
                $data['curr_page'] = 0;
                $this->load->view('template',$data);
            }else {
                $this->load->library('email');
                
                $this->email->from($email, $name);
                $this->email->to('daniel.timov@gmail.com'); 
                
                $this->email->subject('Contacting TecHouse');
                $this->email->message($msg); 
                
                $this->email->send();
                
                $data['main_content'] = 'contact_view';
                $data['curr_page'] = 0;
                $data['success'] = "You successfully sent us a message!";
                $this->load->view('template', $data);
            }
        }
        
    }